package com.rambler.extension.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rambler.extension.entity.ExtSearchEngine;
import com.rambler.extension.vo.ExtUserEngineVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author suhao
 */
@Mapper
public interface ExtSearchEngineMapper extends BaseMapper<ExtSearchEngine> {

    @Select("SELECT " +
            "e.id AS id, " +
            "e.name, " +
            "e.base_url, " +
            "e.icon_base64, " +
            "e.description, " +
            "r.enabled AS enabled " +
            "FROM ext_search_engine e " +
            "INNER JOIN ext_engine_user_rel r ON e.id = r.engine_id " +
            "WHERE r.user_id = #{userId} AND r.enabled = 1 " +
            "ORDER BY e.sort_order ASC")
    List<ExtUserEngineVO> selectUserSearchEngines(@Param("userId") String userId);
}
